package football.haha.com.footballtv.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import football.haha.com.footballtv.FootballApplication;
import football.haha.com.footballtv.R;
import football.haha.com.footballtv.bean.BeanHighLights;
import football.haha.com.footballtv.bean.BeanIndexFootball;
import football.haha.com.footballtv.bean.BeanLookBack;
import football.haha.com.footballtv.bean.BeanSchedule;
import football.haha.com.footballtv.bean.BeanScoreRank;
import football.haha.com.footballtv.bean.BeanSecondFootball;
import football.haha.com.footballtv.bean.BeanShootRank;
import football.haha.com.footballtv.utils.ImageToos;
import football.haha.com.footballtv.utils.Tools;
import football.haha.com.footballtv.view.BorderView;
import football.haha.com.footballtv.view.SmoothHorizontalScrollView;
import football.haha.com.footballtv.view.SmoothVorizontalScrollView;

/**
 * Created by haha on 2017/10/6.
 */

public class LeagueHomeViewActivity extends BaseActivity {

    @Bind(R.id.cb_league_home)
    CheckBox cbLeagueHome;
    @Bind(R.id.cb_schedule)
    CheckBox cbSchedule;
    @Bind(R.id.cb_look_back)
    CheckBox cbLookBack;
    @Bind(R.id.cb_best)
    CheckBox cbBest;
    @Bind(R.id.cb_rank)
    CheckBox cbRank;
    @Bind(R.id.cb_rank_integration)
    CheckBox cbRankIntegration;
    @Bind(R.id.cb_rank_man)
    CheckBox cbRankMan;

    @Bind(R.id.fl_top_check)
    FrameLayout flTopCheck;
    @Bind(R.id.fl_video_look_back_content)
    FrameLayout flVideoLookBackContent;
    @Bind(R.id.fl_video_best_content)
    FrameLayout flVideoBestContent;

    @Bind(R.id.layout_league_home)
    SmoothHorizontalScrollView layoutLeagueHome;
    @Bind(R.id.layout_league_home_content)
    FrameLayout layoutLeagueHomeContent;
    @Bind(R.id.fl_schedule_content)
    FrameLayout flScheduleContent;
    @Bind(R.id.fl_schedule_day)
    FrameLayout flScheduleDay;
    @Bind(R.id.layout_schedule)
    FrameLayout layoutSchedule;
    @Bind(R.id.layout_video_look_back)
    SmoothHorizontalScrollView layoutVideoLookBack;
    @Bind(R.id.layout_video_best)
    SmoothHorizontalScrollView layoutVideoBest;
    @Bind(R.id.ll_main)
    LinearLayout llMain;


    @Bind(R.id.layout_rank_main)
    FrameLayout layoutRankMain;
    @Bind(R.id.layout_rank_man)
    FrameLayout layoutRankMainMan;
    @Bind(R.id.fl_rank_man_content)
    FrameLayout flRankManContent;
    @Bind(R.id.layout_rank_integration)
    FrameLayout layoutRankMainIntegration;
    @Bind(R.id.fl_rank_integration_content)
    FrameLayout flRankIntegrationContent;

    @Bind(R.id.iv_icon)
    ImageView ivIcon;
    @Bind(R.id.rl_left)
    RelativeLayout rlLeft;
    @Bind(R.id.iv_fight_rec_big)
    ImageView ivFightRecBig;
    @Bind(R.id.fl_fight_rec_big)
    FrameLayout flFightRecBig;
    @Bind(R.id.tv_fight_tip1)
    TextView tvFightTip1;
    @Bind(R.id.tv_fight_title1)
    TextView tvFightTitle1;
    @Bind(R.id.ll_fight_rec1)
    LinearLayout llFightRec1;
    @Bind(R.id.tv_fight_tip2)
    TextView tvFightTip2;
    @Bind(R.id.tv_fight_title2)
    TextView tvFightTitle2;
    @Bind(R.id.ll_fight_rec2)
    LinearLayout llFightRec2;
    @Bind(R.id.tv_fight_title3)
    TextView tvFightTitle3;
    @Bind(R.id.tv_buy_tip)
    TextView tvBuyTip;
    @Bind(R.id.tv_name)
    TextView tvName;
    @Bind(R.id.ll_fight_rec_more)
    LinearLayout llFightRecMore;

    @Bind(R.id.svsv_day)
    SmoothVorizontalScrollView svsvDay;
    @Bind(R.id.svsv_schedule)
    SmoothVorizontalScrollView svsvSchedule;
    @Bind(R.id.svsv_rank_integration)
    SmoothVorizontalScrollView svsvRankIntegration;

    public BeanIndexFootball.LeagueMatchListBean.ListBean leagueBean = null;
    public BeanSecondFootball beanSecondFootball = null;
    public BeanScoreRank beanScoreRank = null;
    public BeanShootRank beanShootRank = null;
    public BeanLookBack beanLookBack = null;
    public BeanHighLights beanHighLights = null;
    public ArrayMap<String, BeanSchedule> scheduleArrayMap = new ArrayMap<>();

    public ArrayList<View> homeRecContentList = new ArrayList<>();
    public ArrayList<View> lookbackVideoItemList = new ArrayList<>();
    public ArrayList<View> highLightsItemList = new ArrayList<>();

    public ArrayList<CheckBox> scheduleDayItemList = new ArrayList<>();
    public ArrayList<View> scheduleContentItemList = new ArrayList<>();
    public List<BeanSchedule.ContentsBean> scheduleContentList = new ArrayList<>();

    public int pageIndexLookBack = 1;
    public int pageItemsLookBack = 16;

    public int pageIndexHighLights = 1;
    public int pageItemsHighLights = 16;

    private ArrayList<CheckBox> topTabCheckBoxList = new ArrayList<>();

    private BorderView border;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_league_home);
        ButterKnife.bind(this);

        border = new BorderView(this);
        border.setBackgroundResource(R.drawable.focus_rec_home);
        border.attachTo(layoutLeagueHomeContent);
        border.attachTo(flTopCheck);
        border.attachTo(flScheduleContent);
        border.attachTo(flScheduleDay);
        border.attachTo(flVideoLookBackContent);
        border.attachTo(flVideoBestContent);
        border.attachTo(layoutRankMain);
        border.attachTo(flRankIntegrationContent);
        border.attachTo(flRankManContent);

        createBorderView(llMain);
        showViewByHandler(cbLeagueHome);

        tvBuyTip.setVisibility(View.GONE);

        cbRankIntegration.setOnClickListener(this);
        cbRankMan.setOnClickListener(this);

        topTabCheckBoxList.add(cbLeagueHome);
        topTabCheckBoxList.add(cbSchedule);
        topTabCheckBoxList.add(cbLookBack);
        topTabCheckBoxList.add(cbBest);
        topTabCheckBoxList.add(cbRank);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        if (lookbackVideoItemList.contains(view)){
            BeanLookBack.ContentsBean contentsBean = (BeanLookBack.ContentsBean) view.getTag();
            getAuthPlayUrl(contentsBean.getName(), beanSecondFootball.getCode(), contentsBean.getContentId(),
                    contentsBean.getContentType(), contentsBean.getEndTime());
        }else if (highLightsItemList.contains(view)){
            BeanHighLights.ContentsBean contentsBean = (BeanHighLights.ContentsBean) view.getTag();
            getAuthPlayUrl(contentsBean.getName(), beanSecondFootball.getCode(), contentsBean.getContentId(),
                    contentsBean.getContentType(), contentsBean.getEndTime());
        }else if (scheduleContentItemList.contains(view)){
            BeanSchedule.ContentsBean contentsBean = scheduleContentList.get(scheduleContentItemList.indexOf(view));
            if (!TextUtils.equals("1", contentsBean.getProgramType()) && !TextUtils.equals("2", contentsBean.getProgramType())){ //还未开始 进行预约
                orderData(scheduleContentItemList.indexOf(view));
            }else{
                getAuthPlayUrl(contentsBean.getName(), beanSecondFootball.getCode(), contentsBean.getContentId(),
                        contentsBean.getContentType(), contentsBean.getEndTime());
            }
        }else if (view.getId() == R.id.fl_fight_rec_big){
            playRec(0);
        }else if (view.getId() == R.id.ll_fight_rec1){
            playRec(1);
        }else if (view.getId() == R.id.ll_fight_rec2){
            playRec(2);
        }else if (view.getId() == R.id.ll_fight_rec_more){
            cbLookBack.requestFocus();
        }
    }

    private void playRec(int index){
        try {
            List<BeanSecondFootball.IndexBean.RecommendBean.ListBeanX> recList = beanSecondFootball.getIndex().getRecommend().getList();
            ImageToos.setImageWithUrl(recList.get(0).getLivePicUrl(), ivFightRecBig, FootballApplication.getOptions(R.drawable.default_video));
            BeanSecondFootball.IndexBean.RecommendBean.ListBeanX rec1 = recList.get(index);
            getAuthPlayUrl(rec1.getName(), beanSecondFootball.getCode(), rec1.getContentId(), rec1.getContentType(), rec1.getEndTime());
        }catch (Exception o){
            o.printStackTrace();
        }
    }

    @Override
    public void onFocusChange(View view, boolean b) {
        if (b) {
            if (lookbackVideoItemList.contains(view) || highLightsItemList.contains(view)) {
                scale = 1.15f;
                borderView.setBorderBitmapResId(R.drawable.focus_quare, (int) getResources().getDimension(R.dimen.px80),
                        (int) getResources().getDimension(R.dimen.px95));

                if (lookbackVideoItemList.contains(view) && lookbackVideoItemList.indexOf(view) > (lookbackVideoItemList.size() - 3)
                        && beanLookBack.getTotalPages() > pageIndexLookBack) {
                    pageIndexLookBack++;
                    getLookbackData();
                } else if (highLightsItemList.contains(view) && highLightsItemList.indexOf(view) > (highLightsItemList.size() - 3)
                        && beanHighLights.getTotalPages() > pageIndexLookBack) {
                    pageIndexHighLights++;
                    getHighLights();
                }

            }else if (scheduleDayItemList.contains(view)) {
                borderView.setBorderBitmapResId(R.drawable.fous_left_date_tab, (int) getResources().getDimension(R.dimen.px60));
                for (int i = 0; i < scheduleDayItemList.size(); i++) {
                    scheduleDayItemList.get(i).setChecked(false);
                }
                ((CheckBox) view).setChecked(true);
                getScheduleDayData(Tools.getPastDateYYMMDD(scheduleDayItemList.indexOf(view) - 3));
            }else if (scheduleContentItemList.contains(view)) {
                borderView.setBorderBitmapResId(R.drawable.focus_length, (int) getResources().getDimension(R.dimen.px180),
                        (int) getResources().getDimension(R.dimen.px196));
            }else if (flRankManContent.indexOfChild(view)>-1 || flRankIntegrationContent.indexOfChild(view)>-1) {
                borderView.setBorderBitmapResId(R.drawable.focus_length, (int) getResources().getDimension(R.dimen.px190),
                        (int) getResources().getDimension(R.dimen.px155));
            }else if(homeRecContentList.contains(view)){
                if (homeRecContentList.indexOf(view) % 5==0) {
                    borderView.setBorderBitmapResId(R.drawable.focus_quare, (int) getResources().getDimension(R.dimen.px60),
                            (int) getResources().getDimension(R.dimen.px105));
                }else{
                    borderView.setBorderBitmapResId(R.drawable.focus_quare, (int) getResources().getDimension(R.dimen.px55));
                }
            } else {
                switch (view.getId()) {
                    case R.id.cb_league_home:
                        scale = 1.0f;
                        border.getEffect().setScale(1.1f);
                        borderView.setBorderBitmapResId(R.drawable.focus_tab, (int) getResources().getDimension(R.dimen.px100));
                        cbLeagueHome.setChecked(true);
                        cbSchedule.setChecked(false);
                        cbLookBack.setChecked(false);
                        cbBest.setChecked(false);
                        cbRank.setChecked(false);
                        layoutLeagueHome.setVisibility(View.VISIBLE);
                        layoutSchedule.setVisibility(View.GONE);
                        layoutVideoLookBack.setVisibility(View.GONE);
                        layoutVideoBest.setVisibility(View.GONE);
                        layoutRankMain.setVisibility(View.GONE);
                        break;
                    case R.id.cb_schedule:
                        scale = 1.0f;
                        border.getEffect().setScale(1.1f);
                        borderView.setBorderBitmapResId(R.drawable.focus_tab, (int) getResources().getDimension(R.dimen.px100));
                        cbLeagueHome.setChecked(false);
                        cbSchedule.setChecked(true);
                        cbLookBack.setChecked(false);
                        cbBest.setChecked(false);
                        cbRank.setChecked(false);
                        layoutLeagueHome.setVisibility(View.GONE);
                        layoutSchedule.setVisibility(View.VISIBLE);
                        layoutVideoLookBack.setVisibility(View.GONE);
                        layoutVideoBest.setVisibility(View.GONE);
                        layoutRankMain.setVisibility(View.GONE);
                        if (scheduleDayItemList.size()==0){
                            addScheduleDay();
                        }
                        break;
                    case R.id.cb_look_back:
                        scale = 1.0f;
                        border.getEffect().setScale(1.1f);
                        borderView.setBorderBitmapResId(R.drawable.focus_tab, (int) getResources().getDimension(R.dimen.px100));
                        cbLeagueHome.setChecked(false);
                        cbSchedule.setChecked(false);
                        cbLookBack.setChecked(true);
                        cbBest.setChecked(false);
                        cbRank.setChecked(false);
                        layoutLeagueHome.setVisibility(View.GONE);
                        layoutSchedule.setVisibility(View.GONE);
                        layoutVideoLookBack.setVisibility(View.VISIBLE);
                        layoutVideoBest.setVisibility(View.GONE);
                        layoutRankMain.setVisibility(View.GONE);
                        if (lookbackVideoItemList.size() == 0) {
                            getLookbackData();
                        }
                        break;
                    case R.id.cb_best:
                        scale = 1.0f;
                        border.getEffect().setScale(1.1f);
                        borderView.setBorderBitmapResId(R.drawable.focus_tab, (int) getResources().getDimension(R.dimen.px100));
                        cbLeagueHome.setChecked(false);
                        cbSchedule.setChecked(false);
                        cbLookBack.setChecked(false);
                        cbBest.setChecked(true);
                        cbRank.setChecked(false);
                        layoutLeagueHome.setVisibility(View.GONE);
                        layoutSchedule.setVisibility(View.GONE);
                        layoutVideoLookBack.setVisibility(View.GONE);
                        layoutVideoBest.setVisibility(View.VISIBLE);
                        layoutRankMain.setVisibility(View.GONE);
                        if (highLightsItemList.size() == 0) {
                            getHighLights();
                        }
                        break;
                    case R.id.cb_rank:
                        scale = 1.0f;
                        border.getEffect().setScale(1.0f);
                        borderView.setBorderBitmapResId(R.drawable.focus_tab, (int) getResources().getDimension(R.dimen.px100));
                        cbLeagueHome.setChecked(false);
                        cbSchedule.setChecked(false);
                        cbLookBack.setChecked(false);
                        cbBest.setChecked(false);
                        cbRank.setChecked(true);
                        layoutLeagueHome.setVisibility(View.GONE);
                        layoutSchedule.setVisibility(View.GONE);
                        layoutVideoLookBack.setVisibility(View.GONE);
                        layoutVideoBest.setVisibility(View.GONE);
                        layoutRankMain.setVisibility(View.VISIBLE);
                        if (flRankIntegrationContent.getChildCount() < 2) {
                            getRankData("scoreRank");
                        }
                        break;
                    case R.id.cb_rank_integration:
                        scale = 1.0f;
                        borderView.setBorderBitmapResId(R.drawable.fous_left_date_tab, (int) getResources().getDimension(R.dimen.px60));
                        if (flRankIntegrationContent.getChildCount() < 2) {
                            getRankData("scoreRank");
                        }
                        cbRankIntegration.setChecked(true);
                        cbRankMan.setChecked(false);
                        layoutRankMainIntegration.setVisibility(View.VISIBLE);
                        layoutRankMainMan.setVisibility(View.GONE);
                        break;
                    case R.id.cb_rank_man:
                        scale = 1.0f;
                        borderView.setBorderBitmapResId(R.drawable.fous_left_date_tab, (int) getResources().getDimension(R.dimen.px60));
                        if (flRankManContent.getChildCount() < 2) {
                            getRankData("shootRank");
                        }
                        cbRankIntegration.setChecked(false);
                        cbRankMan.setChecked(true);
                        layoutRankMainIntegration.setVisibility(View.GONE);
                        layoutRankMainMan.setVisibility(View.VISIBLE);
                        break;
                    case R.id.fl_fight_rec_big:
                        scale = 1.0f;
                        borderView.setBorderBitmapResId(R.drawable.focus_big_home, (int) getResources().getDimension(R.dimen.px115));
                        break;
                    case R.id.ll_fight_rec1:
                    case R.id.ll_fight_rec2:
                    case R.id.ll_fight_rec_more:
                        scale = 1.05f;
                        borderView.setBorderBitmapResId(R.drawable.focus_length, (int) getResources().getDimension(R.dimen.px120),
                                (int) getResources().getDimension(R.dimen.px100));
                        break;
                }
            }
        }
        super.onFocusChange(view, b);
    }

    @Override
    public void onBackPressed() {
        if (topTabCheckBoxList.contains(focusView)){
            super.onBackPressed();
        }else{
            for (int i=0; i<topTabCheckBoxList.size(); i++){
                if (topTabCheckBoxList.get(i).isChecked()){
                    topTabCheckBoxList.get(i).requestFocus();
                    break;
                }
            }
        }
    }

    public void addLookbackVideo(List<BeanLookBack.ContentsBean> contentsBeanList) {
        int allWidth = 0;
        int itemStartCount = lookbackVideoItemList.size();
        for (int i = 0; i < contentsBeanList.size(); i++) {
            View itemLookbackVideo = View.inflate(this, R.layout.item_video, null);
            itemLookbackVideo.setOnClickListener(this);
            itemLookbackVideo.setOnFocusChangeListener(this);

            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams((int) getResources().getDimension(R.dimen.px500),
                    (int) getResources().getDimension(R.dimen.px360));


            int topMargin = (int) getResources().getDimension(R.dimen.px90) +
                    (i + itemStartCount) % 2 * (int) getResources().getDimension(R.dimen.px370);
            int leftMargin = (int) getResources().getDimension(R.dimen.px95) +
                    (i + itemStartCount) / 2 * (int) getResources().getDimension(R.dimen.px510);

            params.topMargin = topMargin;
            params.leftMargin = leftMargin;
            params.rightMargin = (int) getResources().getDimension(R.dimen.px95);

            flVideoLookBackContent.addView(itemLookbackVideo, params);
            allWidth = leftMargin + params.width + (int) getResources().getDimension(R.dimen.px95);
            lookbackVideoItemList.add(itemLookbackVideo);

            if (i % 2 == 0) {
                itemLookbackVideo.setNextFocusUpId(R.id.cb_look_back);
            }

            ImageView ivVideo = (ImageView) itemLookbackVideo.findViewById(R.id.iv_video);
            TextView tvTitle = (TextView) itemLookbackVideo.findViewById(R.id.tv_title);
            BeanLookBack.ContentsBean contentsBean = contentsBeanList.get(i);
            ImageToos.setImageWithUrl(contentsBean.getLivePicUrl(), ivVideo, FootballApplication.getOptions(R.drawable.default_video));
            tvTitle.setText(contentsBean.getName());

            itemLookbackVideo.setTag(contentsBean);
        }

        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(allWidth, ViewGroup.LayoutParams.MATCH_PARENT);
        flVideoLookBackContent.setLayoutParams(params);
    }

    public void addHighLights(List<BeanHighLights.ContentsBean> contents) {
        int allWidth = 0;
        int itemStartCount = highLightsItemList.size();
        for (int i = 0; i < contents.size(); i++) {
            View itemHighLights = View.inflate(this, R.layout.item_video, null);
            itemHighLights.setOnFocusChangeListener(this);
            itemHighLights.setOnClickListener(this);
            itemHighLights.setId(i + 2000);
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams((int) getResources().getDimension(R.dimen.px500),
                    (int) getResources().getDimension(R.dimen.px360));

            int topMargin = (int) getResources().getDimension(R.dimen.px90) + (i + itemStartCount) % 2 * (int) getResources().getDimension(R.dimen.px370);
            int leftMargin = (int) getResources().getDimension(R.dimen.px95) + (i + itemStartCount) / 2 * (int) getResources().getDimension(R.dimen.px510);

            params.topMargin = topMargin;
            params.leftMargin = leftMargin;
            params.rightMargin = (int) getResources().getDimension(R.dimen.px95);

            flVideoBestContent.addView(itemHighLights, params);
            allWidth = leftMargin + params.width + (int) getResources().getDimension(R.dimen.px95);
            highLightsItemList.add(itemHighLights);

            if (i % 2 == 0) {
                itemHighLights.setNextFocusUpId(R.id.cb_best);
            }

            ImageView ivVideo = (ImageView) itemHighLights.findViewById(R.id.iv_video);
            TextView tvTitle = (TextView) itemHighLights.findViewById(R.id.tv_title);
            BeanHighLights.ContentsBean contentsBean = contents.get(i);
            List<BeanHighLights.ContentsBean.ImagesBean> imagesBeanList = contentsBean.getImages();
            if (imagesBeanList != null && imagesBeanList.size()>0){
                ImageToos.setImageWithUrl(imagesBeanList.get(0).getUrl(), ivVideo, FootballApplication.getOptions(R.drawable.default_video));
            }
            tvTitle.setText(contentsBean.getName());
            itemHighLights.setTag(contentsBean);
        }

        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(allWidth, ViewGroup.LayoutParams.MATCH_PARENT);
        flVideoBestContent.setLayoutParams(params);

    }

    public void addScheduleDay() {
        int allHeight = 0;
        for (int i = 3; i > -5; i--) {
            CheckBox itemDay = (CheckBox) View.inflate(this, R.layout.item_day, null);
            itemDay.setOnFocusChangeListener(this);
            itemDay.setOnClickListener(this);
            itemDay.setId(i + 2000);
            itemDay.setText(Tools.getPastDate(i));
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams((int) getResources().getDimension(R.dimen.px180),
                    (int) getResources().getDimension(R.dimen.px100));

            int topMargin = (i+4) * (int) getResources().getDimension(R.dimen.px90);
            int leftMargin = (int) getResources().getDimension(R.dimen.px80);

            params.topMargin = topMargin;
            params.leftMargin = leftMargin;

            flScheduleDay.addView(itemDay, params);
            allHeight = topMargin + params.height + (int) getResources().getDimension(R.dimen.px70);

            if (i == 0) {
                itemDay.setChecked(true);
                cbSchedule.setNextFocusDownId(itemDay.getId());
                getScheduleDayData(Tools.getPastDateYYMMDD(0));
            }

            if (i==-4){
                itemDay.setNextFocusUpId(R.id.cb_schedule);
            }

            scheduleDayItemList.add(itemDay);

        }

        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, allHeight);
        flScheduleDay.setLayoutParams(params);
    }

    public void addScheduleContentList(List<BeanSchedule.ContentsBean> contentsBeanList) {
        scheduleContentItemList.clear();
        flScheduleContent.removeAllViews();
        int allHeight = 0;
        for (int i = 0; i < contentsBeanList.size(); i++) {
            View itemSchedule = View.inflate(this, R.layout.item_schedule_football, null);
            itemSchedule.setOnFocusChangeListener(this);
            itemSchedule.setOnClickListener(this);
            itemSchedule.setId(i + 2000);
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    (int) getResources().getDimension(R.dimen.px140));

            int topMargin = i * (int) getResources().getDimension(R.dimen.px150);
            int leftMargin = (int) getResources().getDimension(R.dimen.px320);

            params.topMargin = topMargin;
            params.leftMargin = leftMargin;
            params.rightMargin = (int) getResources().getDimension(R.dimen.px120);

            flScheduleContent.addView(itemSchedule, params);
            allHeight = topMargin + params.height + (int) getResources().getDimension(R.dimen.px150);

            if (i == 0) {
                itemSchedule.setNextFocusUpId(R.id.cb_schedule);
            }
            scheduleContentItemList.add(itemSchedule);

            BeanSchedule.ContentsBean contentsBean = contentsBeanList.get(i);
            TextView tvName = (TextView) itemSchedule.findViewById(R.id.tv_name);
            tvName.setText(contentsBean.getName());
            TextView tvState = (TextView) itemSchedule.findViewById(R.id.tv_state);

            TextView tvOrderState = (TextView) itemSchedule.findViewById(R.id.tv_order_state);

            if (TextUtils.equals("1", contentsBean.getProgramType())){
                tvState.setText("正在直播");
                tvState.setTextColor(0xff48C629);
                tvOrderState.setText("");
            }else if (TextUtils.equals("2", contentsBean.getProgramType())){
                tvState.setText("已结束");
                tvState.setTextColor(0xff268FFB);
                tvOrderState.setText("");
            }else {
                tvState.setText(Tools.getSchedueStartTime(contentsBean.getStartTime()));
                tvState.setTextColor(0xff8D93A2);
            }

            if (Tools.isOrder(this, contentsBean.getContentId())){
                tvOrderState.setText("已预约");
            }else{
                tvOrderState.setText("");
            }

            TextView tvResult = (TextView) itemSchedule.findViewById(R.id.tv_result);
            tvResult.setText(contentsBean.getScore());

            TextView tvLeftTeamName = (TextView) itemSchedule.findViewById(R.id.tv_left_team_name);
            tvLeftTeamName.setText(contentsBean.getHomeTeamName());

            TextView tvRightTeamName = (TextView) itemSchedule.findViewById(R.id.tv_right_team_name);
            tvRightTeamName.setText(contentsBean.getAwayTeamName());

            ImageView ivLeftIcon = (ImageView) itemSchedule.findViewById(R.id.iv_left_team_icon);
            ImageView ivRightIcon = (ImageView) itemSchedule.findViewById(R.id.iv_right_team_icon);

            ImageToos.setImageWithUrl(contentsBean.getHomeTeamLogo(), ivLeftIcon, FootballApplication.getOptions(R.drawable.default_team));
            ImageToos.setImageWithUrl(contentsBean.getAwayTeamLogo(), ivRightIcon, FootballApplication.getOptions(R.drawable.default_team));

        }

        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, allHeight);
        flScheduleContent.setLayoutParams(params);
    }

    public void addRankIntegration() {
        int allHeight = 0;
        List<BeanScoreRank.DataBean.ListBean> listBeans = beanScoreRank.getData().getList();
        for (int i = 0; i < listBeans.size(); i++) {

            BeanScoreRank.DataBean.ListBean bean = listBeans.get(i);

            LinearLayout itemRankIntegration = (LinearLayout) View.inflate(this, R.layout.item_rank_integration, null);
            itemRankIntegration.setOnFocusChangeListener(this);
            itemRankIntegration.setNextFocusLeftId(R.id.cb_rank_integration);
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) getResources().getDimension(R.dimen.px98));

            int topMargin = i * (int) getResources().getDimension(R.dimen.px100);

            params.topMargin = topMargin;

            flRankIntegrationContent.addView(itemRankIntegration, params);
            allHeight = topMargin + params.height + (int) getResources().getDimension(R.dimen.px70);

            if (i == 0) {
                itemRankIntegration.setNextFocusUpId(R.id.cb_rank);
            }

            //排名
            TextView tvIndex = (TextView) itemRankIntegration.getChildAt(0);
            tvIndex.setText("" + (i+1));

            //图标
            ImageView ivTeamIcon = (ImageView) itemRankIntegration.findViewById(R.id.iv_team_icon);
            ImageToos.setImageWithUrl(bean.getTeamLogo(), ivTeamIcon, FootballApplication.getOptions(R.drawable.default_team));

            //团名
            TextView tvTeamName = (TextView) itemRankIntegration.findViewById(R.id.tv_team_name);
            tvTeamName.setText(bean.getTeamName());

            //场次
            TextView tvNum = (TextView) itemRankIntegration.getChildAt(2);
            tvNum.setText(bean.getMatchNum()+"");

            //积分
            TextView tvIntegration = (TextView) itemRankIntegration.getChildAt(3);
            tvIntegration.setText(bean.getScore()+"");

            //胜
            TextView tvWinNum = (TextView) itemRankIntegration.getChildAt(4);
            tvWinNum.setText(bean.getWinNum()+"");

            //平
            TextView tvNormalNum = (TextView) itemRankIntegration.getChildAt(5);
            tvNormalNum.setText(bean.getDrawNum()+"");

            //负
            TextView tvLostNum = (TextView) itemRankIntegration.getChildAt(6);
            tvLostNum.setText(bean.getLoseNum()+"");

            //进球
            TextView tv6 = (TextView) itemRankIntegration.getChildAt(7);
            tv6.setText(bean.getGoalsNum()+"");

            //失球
            TextView tv7 = (TextView) itemRankIntegration.getChildAt(8);
            tv7.setText(bean.getLoseGoalsNum()+"");

            //净胜球
            TextView tv8 = (TextView) itemRankIntegration.getChildAt(9);
            tv8.setText((bean.getGoalsNum()-bean.getLoseGoalsNum())+"");

        }

        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, allHeight);
        flRankIntegrationContent.setLayoutParams(params);
    }

    public void addRankMan() {
        int allHeight = 0;
        List<BeanShootRank.DataBean.ListBean> listBeans = beanShootRank.getData().getList();
        for (int i = 0; i < listBeans.size(); i++) {

            BeanShootRank.DataBean.ListBean bean = listBeans.get(i);

            LinearLayout itemRankMan = (LinearLayout) View.inflate(this, R.layout.item_rank_man, null);
            itemRankMan.setOnFocusChangeListener(this);
            itemRankMan.setNextFocusLeftId(R.id.cb_rank_man);
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) getResources().getDimension(R.dimen.px98));

            int topMargin = i * (int) getResources().getDimension(R.dimen.px101);

            params.topMargin = topMargin;

            flRankManContent.addView(itemRankMan, params);
            allHeight = topMargin + params.height + (int) getResources().getDimension(R.dimen.px70);

            if (i == 0) {
                itemRankMan.setNextFocusUpId(R.id.cb_rank);
            }

            //排名
            TextView tvIndex = (TextView) itemRankMan.getChildAt(0);
            tvIndex.setText("" + (i+1));

            //球员
            TextView tvTeamName = (TextView) itemRankMan.getChildAt(1);
            tvTeamName.setText(bean.getPlayerName());

            //球队
            TextView tvNum = (TextView) itemRankMan.getChildAt(2);
            tvNum.setText(bean.getTeamName());

            //总进球数
            TextView tvIntegration = (TextView) itemRankMan.getChildAt(3);
//            tvIntegration.setText(bean.get);

            //普通球数
            TextView tvWinNum = (TextView) itemRankMan.getChildAt(4);
            tvWinNum.setText("4");

            //点球
            TextView tvNormalNum = (TextView) itemRankMan.getChildAt(5);
            tvNormalNum.setText("5");

            //乌龙球
            TextView tvLostNum = (TextView) itemRankMan.getChildAt(6);
            tvLostNum.setText("6");
        }

        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, allHeight);
        flRankManContent.setLayoutParams(params);
    }


    public void getLookbackData() {

    }

    public void getHighLights() {

    }

    public void getScheduleDayData(String day) {

    }

    public void getRankData(String type) {

    }

    public void addFocusListener(View view){
        view.setOnFocusChangeListener(this);
    }

    public void orderData(int index){

    }

}
